package com.secsbrain.engine.biz.utils;

import java.util.List;
import java.util.stream.Collectors;

import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.task.Task;

import com.secsbrain.engine.client.model.HistoryTask;
import com.secsbrain.engine.client.model.TaskDto;

/**
 * 对象转换工具类
 *
 * @author zhaoyi
 */
public class ParseDtoUtil {
	
	public static TaskDto parseTask(Task org){
		TaskDto taskInfo = new TaskDto();
    	taskInfo.setAssigne(org.getAssignee());
    	taskInfo.setCreateTime(org.getCreateTime());
    	taskInfo.setId(org.getId());
    	taskInfo.setName(org.getName());
    	taskInfo.setKey(org.getTaskDefinitionKey());
    	taskInfo.setProcessInstanceId(org.getProcessInstanceId());
    	return taskInfo;
	}
    
	/**
     * 功能描述: <br>
     * 任务列表对象转换
     *
     * @param taskList
     * @return
     */
    public static List<TaskDto> parseTaskList(List<Task> taskList){
    	List<TaskDto> taskInfoList = taskList.stream().map(org->{
        	return parseTask(org);
        }).collect(Collectors.toList());
    	return taskInfoList;
    }
    
    /**
     * 功能描述: <br>
     * 历史任务列表对象转换
     *
     * @param historicActivityInstances
     * @return
     */
    public static List<HistoryTask> parseHistoryList(List<HistoricActivityInstance> historicActivityInstances){
    	List<HistoryTask> historyTaskList = historicActivityInstances.stream().map(historicActivityInstance->{
    		HistoryTask historyTask=new HistoryTask();

    		historyTask.setId(historicActivityInstance.getId());
    		historyTask.setActivityName(historicActivityInstance.getActivityName());
    		historyTask.setAssignee(historicActivityInstance.getAssignee());
    		historyTask.setProcessInstanceId( historicActivityInstance.getProcessInstanceId());
    		historyTask.setTaskId(historicActivityInstance.getTaskId());
    		historyTask.setStartTime(historicActivityInstance.getStartTime());
    		historyTask.setEndTime(historicActivityInstance.getEndTime());
        	return historyTask;
        }).collect(Collectors.toList());
    	return historyTaskList;
    }
    
}
